/**
 * 
 */
package fr.fermeManager.application.views.utils;

import java.awt.Color;
import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

import fr.fermeManager.application.views.ViewGestionTypesTransactions;
import fr.fermeManager.library.model.beans.TypeTransaction;

/**
 * @author Mo
 *
 */
public class RenderTreeTypeTransaction extends DefaultTreeCellRenderer{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value,boolean selected, boolean expanded, boolean leaf, int row,boolean hasFocus) {
		
		super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
        
		TypeTransaction typeTransacTmp = (TypeTransaction) ((DefaultMutableTreeNode) value).getUserObject();
		
		if(typeTransacTmp.isEstSortie()){
			this.setText(typeTransacTmp.getLibelle());
			this.setIcon(createImageIcon("/img16x16/fleche_rouge.png"));
		}else{
			this.setText(typeTransacTmp.getLibelle());
			this.setIcon(createImageIcon("/img16x16/fleche_verte.png"));
		}
		if(!typeTransacTmp.isActif()){
			setForeground(Color.RED);
		}

		return this;
	}
	
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = ViewGestionTypesTransactions.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }

}
